package org.zzk.dao;

import com.google.gson.JsonObject;
import io.netty.channel.Channel;
import lombok.Data;

@Data
public class Player {
    private final String id;
    private final Channel channel;
    private final int gameTimeLimitMs;
    private final int stepTimeLimitMs;
    private boolean isRed;

    public Player(String id, Channel channel, int gameTimeLimitMs, int stepTimeLimitMs, boolean isRed) {
        this.id = id;
        this.channel = channel;
        this.gameTimeLimitMs = gameTimeLimitMs;
        this.stepTimeLimitMs = stepTimeLimitMs;
        this.isRed = isRed;
    }

    public void sendPacket(ChessPacket packet) {
        channel.writeAndFlush(packet);
    }

    public JsonObject getPlayerInfo() {
        JsonObject json = new JsonObject();
        json.addProperty("id", getId());
        json.addProperty("isRed", isRed() ? "true" : "false");
        return json;
    }
}
